﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSConsoleTest
{
    class TestInterface : BaseConsoleTest
    {
        public void printDescription()
        {
            Console.WriteLine("--- Interface ---");
        }

        public void doTest()
        {
            object[] robots = new object[] {new DogRobot(), new SnakeRobot() };

            foreach(object robot in robots) 
            {
                IAttackable attackable = robot as IAttackable;
                if (attackable != null)
                {
                    attackable.attack();
                }

                IDependable dependable = robot as IDependable;
                if (dependable != null)
                {
                    dependable.depend();
                }
            }
        }
    }

    interface IAttackable
    {
        void attack();
    }

    interface IDependable
    {
        void depend();
    }

    class DogRobot : IAttackable, IDependable
    {
        public void attack()
        {
            Console.WriteLine("bite attack");
        }

        public void depend()
        {
            Console.WriteLine("raise front legs");
        }
    }

    class SnakeRobot : IAttackable, IDependable
    {
        public void attack()
        {
            Console.WriteLine("posion attack");
        }

        public void depend()
        {
            Console.WriteLine("flee!!");
        }
    }
}
